package com.ben.multiple.poi;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;

/**
 * @author BenJin Yin
 * @date 2020/6/30
 */
@SpringBootTest
public class ExportRest {
    static final String URL_PREFIX = "http://localhost:9009/export";
    static TestRestTemplate restTemplate = new TestRestTemplate(new RestTemplateBuilder());

    @Test
    void export() throws IOException {
        long start = System.currentTimeMillis();
        String url = URL_PREFIX;
        ResponseEntity<byte[]> entity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(null), byte[].class);
        FileOutputStream out = new FileOutputStream(new File("D:\\q5.xlsx"));
        out.write(entity.getBody());
        out.close();
        System.out.println("ok===" + (System.currentTimeMillis() - start));
    }

}
